# def add(a = 2,b = 8):
#     return  a + b
# print(add(1,2))
# print(add())



#  *args 只能传tuple类型
# def add(*args):
#     print(args,type(args))
# add((1,2,3))



#  *args 只能传dict类型
# def add(**args):
#     print(args,type(args))
# add(name='hello',age=12)


#函数返回值
# def calu(a,b):
#     """
#     加分和减法
#
#     :param a: 参数a
#     :param b: 参数b
#     :return:  元祖()
#     """
#     sum = a+b
#     sub = a-b
#     return (sum,sub)
# reslut1,result2 = calu(5,4) #元祖解包
# print(reslut1,result2)


#偏函数
# def test(a,b,c,d = 2):
#     print(a + b + c + d)
#
# import  functools
# newTest = functools.partial(test,b=6)
# newTest(1,c=2)


# 偏函数使用场景
# import  functools
# myInt = functools.partial(int,base=2)
# print(myInt('1011'))


# # 高阶函数
# def getKey(x):
#     return x['age']
#
# p = [{'name':'sz','age':19},{'name':'sz3','age':12},{'name':'sz2','age':17}]
# print(sorted(p,key=getKey))


#匿名函数
# p = [{'name':'sz','age':19},{'name':'sz3','age':12},{'name':'sz2','age':17}]
# print(sorted(p,key=lambda x:x['age']))


#闭包
# def lineConfig(name,w):
#     def line():
#         print("_ " * (w//2) + name + "_ " * (w//2))
#
#     return line
# line = lineConfig('hello',20)
# line()


#
# def iner():
#     num = 10
#     def outer():
#         num = 666
#         print(num)
#     print(num)
#     outer()
#     print(num)
#     return outer
#
# iner()()


# def iner():
#     num = 10
#     def outer():
#         nonlocal num
#         num = 666
#         print(num)
#     print(num)
#     outer()
#     print(num)
#     return outer
#
# iner()()















